package cn.lcsjsxy.yxc.servlet;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.FileOutputStream;
import java.io.IOException;

@WebServlet(value = "/servlet3")
public class ServletTest3 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context = getServletContext();

        //获得一个指向项目部署位置下的某个文件或某个目录的磁盘真实路径的API
        String path=context.getRealPath("upload");
        System.out.println(path);

        //获得项目部署的上下文路径，项目的访问路径
        //后续我们会学习i在项目中使用相对和绝对路找目标资源
        //servlet1      /d03/servlet1
        String contextPath=context.getContextPath();
        System.out.println(contextPath);
    }
}
